//
//  AFClient.m
//  noteMan
//
//  Created by 周博 on 16/12/12.
//  Copyright © 2016年 BogoZhou. All rights reserved.
//

#import "AFClient.h"

@interface AFClient ()<NSURLSessionDelegate>
{
    NSString *_url;
}
@end

@implementation AFClient


+(instancetype)shareInstance{
    static AFClient *defineAFClient = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        defineAFClient = [[AFClient alloc] init];
    });
    return defineAFClient;
}

- (NSData *)resetSizeOfImageData:(UIImage *)source_image maxSize:(NSInteger)maxSize
{
    //先调整分辨率
    CGSize newSize = CGSizeMake(source_image.size.width, source_image.size.height);
    
    CGFloat tempHeight = newSize.height / 1024;
    CGFloat tempWidth = newSize.width / 1024;
    
    if (tempWidth > 1.0 && tempWidth > tempHeight) {
        newSize = CGSizeMake(source_image.size.width / tempWidth, source_image.size.height / tempWidth);
    }
    else if (tempHeight > 1.0 && tempWidth < tempHeight){
        newSize = CGSizeMake(source_image.size.width / tempHeight, source_image.size.height / tempHeight);
    }
    
    UIGraphicsBeginImageContext(newSize);
    [source_image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    //调整大小
    NSData *imageData = UIImageJPEGRepresentation(newImage,1.0);
    NSUInteger sizeOrigin = [imageData length];
    NSUInteger sizeOriginKB = sizeOrigin / 1024;
    if (sizeOriginKB > maxSize) {
        NSData *finallImageData = UIImageJPEGRepresentation(newImage,0.50);
        return finallImageData;
    }
    
    return imageData;
}

- (AFHTTPSessionManager *)creatManager{

    AFHTTPSessionManager* mgr = [AFHTTPSessionManager manager];
    
//        mgr.requestSerializer = [AFHTTPRequestSerializer serializer];
    AFSecurityPolicy *securityPolicy = [AFSecurityPolicy defaultPolicy];
    //allowInvalidCertificates 是否允许无效证书（也就是自建的证书），默认为NO//如果是需要验证自建证书，需要设置为YES
    securityPolicy.allowInvalidCertificates = YES;
    //validatesDomainName 是否需要验证域名，默认为YES；
    securityPolicy.validatesDomainName = NO;
    
    mgr.securityPolicy  = securityPolicy;
    mgr.requestSerializer = [AFHTTPRequestSerializer serializer];
    mgr.responseSerializer = [AFHTTPResponseSerializer serializer];
    [mgr.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    return mgr;
}

- (void)requestSettingByUrl:(NSString *)url jsonString:(NSString *)jsonString progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSData *postData = [jsonString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    
    NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:_url parameters:nil error:nil];
    request.timeoutInterval= [[[NSUserDefaults standardUserDefaults] valueForKey:@"timeoutInterval"] longValue];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setHTTPBody:postData];
    
    [[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
        if (!error) {
            NSLog(@"responseObject: %@", responseObject);
            if (success) {
                success(responseObject);
            }
        } else {
            NSLog(@"error: %@, %@, %@", error, response, responseObject);
            if (failure) {
                failure(error);
            }
        }
    }] resume];
}

- (void)requestGETSettingByUrl:(NSString *)url jsonString:(NSString *)jsonString progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    
    NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"GET" URLString:_url parameters:nil error:nil];
    request.timeoutInterval= [[[NSUserDefaults standardUserDefaults] valueForKey:@"timeoutInterval"] longValue];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    
    [[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
        if (!error) {
            NSLog(@"responseObject: %@", responseObject);
            if (success) {
                success(responseObject);
            }
        } else {
            NSLog(@"error: %@, %@, %@", error, response, responseObject);
            if (failure) {
                failure(error);
            }
        }
    }] resume];
}

#pragma mark - Verson 1

//0.获取服务器时间戳
- (void)getSeverDateProgressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    _url = [NSString stringWithFormat:@"%@/v1/config/timestamp",kHttpHeader];
    AFHTTPSessionManager *manager = [self creatManager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:_url parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (success) {
            NSString *dateString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
            success(dateString);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
    
    
}

//1.商家登录
- (void)getCodeByMobile:(NSString *)mobile progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/sms/send";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];

    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:mobile forKey:@"mobile"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];

        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }        }
    }];

}

//2.登录：通过短信验证码
- (void)loginByMobile:(NSString *)mobile code:(NSString *)code progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/sms/check_code_login";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:mobile forKey:@"mobile"];
    [dict setValue:code forKey:@"code"];
    
    [dict setValue:@"1" forKey:@"device_type"];
    [dict setValue:@"0" forKey:@"brand"];
    [dict setValue:[BGFunctionHelper deviceVersion] forKey:@"model"];
    [dict setValue:@"0" forKey:@"version_sdk"];
    [dict setValue:[BGFunctionHelper getCurrentIOS] forKey:@"version_release"];
    [dict setValue:kAppVersion forKey:@"software_version"];

    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }        }
    }];

}

//3.身份检查
- (void)checkMobile:(NSString *)mobile progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/employee/check_identity";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:mobile forKey:@"mobile"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];

}

//4.权限菜单
- (void)getMenuByEid:(NSString *)eid progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/employee/functions";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:eid forKey:@"eid"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//设为已铺设
- (void)setToHasUsedById:(NSString *)shopId eid:(NSString *)eid progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/store/already_laid";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:shopId forKey:@"id"];
    [dict setValue:eid forKey:@"eid"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//删除(将已铺设店铺删除)
- (void)deleteShopById:(NSString *)shopId eid:(NSString *)eid progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/store/delete";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:shopId forKey:@"id"];
    [dict setValue:eid forKey:@"eid"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//7.更新店铺信息
- (void)updateShopInfoByShopId:(NSString *)shopId eid:(NSString *)eid name:(NSString *)name contact:(NSString *)contact tel:(NSString *)tel latitude:(NSString *)latitude longitude:(NSString *)longitude province_id:(NSString *)province_id city_id:(NSString *)city_id area_id:(NSString *)area_id specific_address:(NSString *)specific_address province_name:(NSString *)province_name city_name:(NSString *)city_name area_name:(NSString *)area_name position:(NSString *)position position_name:(NSString *)position_name img_url:(NSString *)img_url from_type:(NSString *)from_type remark:(NSString *)remark progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/store/update";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:shopId forKey:@"id"];
    [dict setValue:eid forKey:@"eid"];
    
    if (![BGFunctionHelper isNULLOfString:name]) {
        [dict setValue:name forKey:@"name"];
    }
    if (![BGFunctionHelper isNULLOfString:contact]) {
        [dict setValue:contact forKey:@"contact"];
    }
    if (![BGFunctionHelper isNULLOfString:tel]) {
        [dict setValue:tel forKey:@"tel"];
    }
    if (![BGFunctionHelper isNULLOfString:latitude]) {
        [dict setValue:latitude forKey:@"latitude"];
    }
    if (![BGFunctionHelper isNULLOfString:longitude]) {
        [dict setValue:longitude forKey:@"longitude"];
    }
    if (![BGFunctionHelper isNULLOfString:province_id]) {
        [dict setValue:province_id forKey:@"province_id"];
    }
    if (![BGFunctionHelper isNULLOfString:city_id]) {
        [dict setValue:city_id forKey:@"city_id"];
    }
    if (![BGFunctionHelper isNULLOfString:area_id]) {
        [dict setValue:area_id forKey:@"area_id"];
    }
    if (![BGFunctionHelper isNULLOfString:specific_address]) {
        [dict setValue:specific_address forKey:@"specific_address"];
    }
    if (![BGFunctionHelper isNULLOfString:province_name]) {
        [dict setValue:province_name forKey:@"province_name"];
    }
    if (![BGFunctionHelper isNULLOfString:city_name]) {
        [dict setValue:city_name forKey:@"city_name"];
    }
    if (![BGFunctionHelper isNULLOfString:area_name]) {
        [dict setValue:area_name forKey:@"area_name"];
    }
    if (![BGFunctionHelper isNULLOfString:position]) {
        [dict setValue:position forKey:@"position"];
    }
    if (![BGFunctionHelper isNULLOfString:position_name]) {
        [dict setValue:position_name forKey:@"position_name"];
    }
    if (![BGFunctionHelper isNULLOfString:img_url]) {
        [dict setValue:img_url forKey:@"img_url"];
    }
    if (![BGFunctionHelper isNULLOfString:from_type]) {
        [dict setValue:from_type forKey:@"from_type"];
    }
    if (![BGFunctionHelper isNULLOfString:remark]) {
        [dict setValue:remark forKey:@"remark"];
    }

    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//8.新建店铺信息
- (void)newShopInfoByEid:(NSString *)eid name:(NSString *)name contact:(NSString *)contact tel:(NSString *)tel latitude:(NSString *)latitude longitude:(NSString *)longitude province_id:(NSString *)province_id city_id:(NSString *)city_id area_id:(NSString *)area_id specific_address:(NSString *)specific_address province_name:(NSString *)province_name city_name:(NSString *)city_name area_name:(NSString *)area_name position:(NSString *)position position_name:(NSString *)position_name img_url:(NSString *)img_url from_type:(NSString *)from_type remark:(NSString *)remark progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/store/insert";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    
    if (![BGFunctionHelper isNULLOfString:name]) {
        [dict setValue:name forKey:@"name"];
    }
    if (![BGFunctionHelper isNULLOfString:contact]) {
        [dict setValue:contact forKey:@"contact"];
    }
    if (![BGFunctionHelper isNULLOfString:tel]) {
        [dict setValue:tel forKey:@"tel"];
    }
    if (![BGFunctionHelper isNULLOfString:latitude]) {
        [dict setValue:latitude forKey:@"latitude"];
    }
    if (![BGFunctionHelper isNULLOfString:longitude]) {
        [dict setValue:longitude forKey:@"longitude"];
    }
    if (![BGFunctionHelper isNULLOfString:province_id]) {
        [dict setValue:province_id forKey:@"province_id"];
    }
    if (![BGFunctionHelper isNULLOfString:city_id]) {
        [dict setValue:city_id forKey:@"city_id"];
    }
    if (![BGFunctionHelper isNULLOfString:area_id]) {
        [dict setValue:area_id forKey:@"area_id"];
    }
    if (![BGFunctionHelper isNULLOfString:specific_address]) {
        [dict setValue:specific_address forKey:@"specific_address"];
    }
    if (![BGFunctionHelper isNULLOfString:province_name]) {
        [dict setValue:province_name forKey:@"province_name"];
    }
    if (![BGFunctionHelper isNULLOfString:city_name]) {
        [dict setValue:city_name forKey:@"city_name"];
    }
    if (![BGFunctionHelper isNULLOfString:area_name]) {
        [dict setValue:area_name forKey:@"area_name"];
    }
    if (![BGFunctionHelper isNULLOfString:position]) {
        [dict setValue:position forKey:@"position"];
    }
    if (![BGFunctionHelper isNULLOfString:position_name]) {
        [dict setValue:position_name forKey:@"position_name"];
    }
    if (![BGFunctionHelper isNULLOfString:img_url]) {
        [dict setValue:img_url forKey:@"img_url"];
    }
    if (![BGFunctionHelper isNULLOfString:from_type]) {
        [dict setValue:from_type forKey:@"from_type"];
    }
    if (![BGFunctionHelper isNULLOfString:remark]) {
        [dict setValue:remark forKey:@"remark"];
    }
    
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//商家分页信息
- (void)getShopListByEid:(NSString *)eid page_size:(NSString *)page_size page_index:(NSString *)page_index status:(NSString *)status store_type:(NSString *)store_type progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/store/page";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:page_size forKey:@"page_size"];
    [dict setValue:page_index forKey:@"page_index"];
    if (![BGFunctionHelper isNULLOfString:status]) {
        [dict setValue:status forKey:@"status"];
    }
    if (![BGFunctionHelper isNULLOfString:store_type]) {
        [dict setValue:store_type forKey:@"store_type"];
    }

    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//10.所属充电宝
- (void)powerBelongByShopId:(NSString *)shopId eid:(NSString *)eid page_size:(NSString *)page_size page_index:(NSString *)page_index progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/store/charging_page";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:shopId forKey:@"id"];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:page_size forKey:@"page_size"];
    [dict setValue:page_index forKey:@"page_index"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}


//解析扫一扫得到的字符串
- (void)upLoadQRCodeInfoByEid:(NSString *)eid qrcode:(NSString *)qrcode progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v2/qrcode/parse";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:qrcode forKey:@"qrcode"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//查找充电宝
- (void)findPowerByEid:(NSString *)eid alias:(NSString *)alias progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/get";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//查找充电宝 手写
- (void)findPowerWriteByEid:(NSString *)eid alias:(NSString *)alias progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/get_input";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//激活充电宝
- (void)activePowerByEid:(NSString *)eid alias:(NSString *)alias name:(NSString *)name remark:(NSString *)remark store_info_id:(NSString *)store_info_id latitude:(NSString *)latitude longitude:(NSString *)longitude progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/activation";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    if (![BGFunctionHelper isNULLOfString:name]) {
        [dict setValue:name forKey:@"name"];
    }
    if (![BGFunctionHelper isNULLOfString:remark]) {
        [dict setValue:remark forKey:@"remark"];
    }
    
    if (![BGFunctionHelper isNULLOfString:latitude]) {
        [dict setValue:latitude forKey:@"latitude"];
    }
    if (![BGFunctionHelper isNULLOfString:longitude]) {
        [dict setValue:longitude forKey:@"longitude"];
    }
    
    [dict setValue:store_info_id forKey:@"store_info_id"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    
//    NSLog(@"激活充电宝 -》 %@",dict);
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//更新充电宝
- (void)updatePowerByEid:(NSString *)eid alias:(NSString *)alias name:(NSString *)name remark:(NSString *)remark store_info_id:(NSString *)store_info_id progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/update";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    if (![BGFunctionHelper isNULLOfString:name]) {
        [dict setValue:name forKey:@"name"];
    }
    if (![BGFunctionHelper isNULLOfString:remark]) {
        [dict setValue:remark forKey:@"remark"];
    }
    [dict setValue:store_info_id forKey:@"store_info_id"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//指令：查询是否成功通知了充电宝
- (void)checkPostToPowerByMessage_id:(NSString *)message_id progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/message_status";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:message_id forKey:@"message_id"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//指令：通知充电
- (void)postNotiToGetPowerByEid:(NSString *)eid alias:(NSString *)alias progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/start_charging";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//指令：检查状态（在线）
- (void)checkTypeGetPowerByEid:(NSString *)eid alias:(NSString *)alias progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/check_status";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//撤回设备
- (void)recallPowerByEid:(NSString *)eid alias:(NSString *)alias progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/withdraw";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//硬件故障
- (void)brokenPowerByEid:(NSString *)eid alias:(NSString *)alias content:(NSString *)content progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/hardware_fault";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    [dict setValue:content forKey:@"content"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//指令：查询固件
- (void)findPowerNotiByPowerByEid:(NSString *)eid alias:(NSString *)alias progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/query_sv";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//指令：更新固件
- (void)updatePowerVersonByEid:(NSString *)eid alias:(NSString *)alias progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/update_sv";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//获取充电宝版本
- (void)getNewVersonAboutPowerProgressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/version/firmware";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];

}



//获取最新版本
- (void)getNewVersonProgressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/version/release";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        NSLog(@"反问");
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}
#pragma mark - 上传图片


- (void)uploadImageByImage:(UIImage *)image progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    
    NSData *imageData = UIImageJPEGRepresentation(image, 0.5);

    // 访问路径
    NSString *urlString = @"/app/v1/file/upload";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    NSString *encry = [NSString stringWithFormat:@"%@=%@&%@=%@&%@=%@&%@=%@&%@=%@%@",@"i",urlString,@"rf",@"1",@"ts",kNowDate,@"udid",UDID,@"v",kAppVersion,kKey];
    NSString *encryCode = [BGFunctionHelper md5:encry];
    [dict setValue:encryCode forKey:@"encry"];
    
    [manager POST:_url parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        // 上传文件
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat            = @"yyyyMMddHHmmss";
        NSString *str                         = [formatter stringFromDate:[NSDate date]];
        NSString *fileName               = [NSString stringWithFormat:@"%@.jpg", str];
        
        [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpg"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}


- (void)postUPdateWiFiInfoByStaN:(NSString *)staN staP:(NSString *)staP mac:(NSString *)mac ver:(NSString *)ver ProgressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    _url = @"http://192.168.4.1/wifi_set.html";
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:staN,@"staN",staP,@"staP",mac,@"mac",ver,@"ver", nil];
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
//            kAlert(@"WiFi配置信息已发出，设备正在重启");
        }
    }];
}

// 取参数 http://192.168.4.1/sta_para.js# 获取硬件信息

- (void)getMacInfoProgressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    _url = @"http://192.168.4.1/sta_para.js#";
    AFHTTPSessionManager *manager = [self creatManager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:_url parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (success) {
            NSString *dateString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
            success(dateString);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//获取统计数据
- (void)getMainMessageByUserId:(NSString *)eid ProgressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/employee/statistics";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//分页信息（简单数据）
- (void)getShopSimpleListByEid:(NSString *)eid page_size:(NSString *)page_size page_index:(NSString *)page_index status:(NSString *)status progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/store/simple_page";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:page_size forKey:@"page_size"];
    [dict setValue:page_index forKey:@"page_index"];
    if (![BGFunctionHelper isNULLOfString:status]) {
        [dict setValue:status forKey:@"status"];
    }
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }

        }
    }];
}

//单个店铺按日期查询
- (void)SingleShopSearchByEid:(NSString *)eid sid:(NSString *)sid start_date:(NSString *)start_date end_date:(NSString *)end_date progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/statistics/store";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:sid forKey:@"sid"];
    [dict setValue:start_date forKey:@"start_date"];
    [dict setValue:end_date forKey:@"end_date"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
        if (error.code == -1009) {
            kAlert(@"似乎已断开与互联网的连接");
        }else{
            NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
            kAlert(errorString);
        }
    }];
}


//指令：控制绿灯
- (void)contrlLightByAlias:(NSString *)alias eid:(NSString *)eid status:(NSString *)status progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/green_lighting";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:alias forKey:@"alias"];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:status forKey:@"status"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
        if (error.code == -1009) {
            kAlert(@"似乎已断开与互联网的连接");
        }else{
            NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
            kAlert(errorString);
        }
    }];
}

//个人历史统计
- (void)userHistorySearchByEid:(NSString *)eid start_date:(NSString *)start_date end_date:(NSString *)end_date progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/statistics/employee_history";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:start_date forKey:@"start_date"];
    [dict setValue:end_date forKey:@"end_date"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
        if (error.code == -1009) {
            kAlert(@"似乎已断开与互联网的连接");
        }else{
            NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
            kAlert(errorString);
        }
    }];
}

//进入 统计数据里面的页面要的数据
- (void)tongjiByEid:(NSString *)eid date:(NSString *)date progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v2/statistics/employee_all";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:date forKey:@"date"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
        if (error.code == -1009) {
            kAlert(@"似乎已断开与互联网的连接");
        }else{
            NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
            kAlert(errorString);
        }
    }];
}

//店铺今日达标情况
- (void)dabiaoByEid:(NSString *)eid page_size:(NSString *)page_size page_index:(NSString *)page_index progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/employee/store_realtime_ok";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:page_size forKey:@"page_size"];
    [dict setValue:page_index forKey:@"page_index"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
        if (error.code == -1009) {
            kAlert(@"似乎已断开与互联网的连接");
        }else{
            NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
            kAlert(errorString);
        }
    }];
}

//个人提成历史记录
- (void)GetCommistionHistoryInfoByEid:(NSString *)eid start_date:(NSString *)start_date end_date:(NSString *)end_date progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v2/statistics/commistion_history";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:start_date forKey:@"start_date"];
    [dict setValue:end_date forKey:@"end_date"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
        if (error.code == -1009) {
            kAlert(@"似乎已断开与互联网的连接");
        }else{
            NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
            kAlert(errorString);
        }
    }];
}

//寄回工厂
- (void)sendFactoryByEid:(NSString *)eid alias:(NSString *)alias progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/send_factory";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//已安装充电宝分页
- (void)hasInstalledPowerByEid:(NSString *)eid page_size:(NSString *)page_size page_index:(NSString *)page_index electricity_sc_status:(NSString *)electricity_sc_status on_line_sc_status:(NSString *)on_line_sc_status on_line:(NSString *)on_line dump_energy_per:(NSString *)dump_energy_per offline_day:(NSString *)offline_day device_type:(NSString *)device_type progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    
    NSString *urlString = @"/app/v1/charging/page";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:page_size forKey:@"page_size"];
    [dict setValue:page_index forKey:@"page_index"];

    if (![BGFunctionHelper isNULLOfString:electricity_sc_status]) {
        [dict setValue:electricity_sc_status forKey:@"electricity_sc_status"];
    }
    if (![BGFunctionHelper isNULLOfString:on_line_sc_status]) {
        [dict setValue:on_line_sc_status forKey:@"on_line_sc_status"];
    }
    if (![BGFunctionHelper isNULLOfString:on_line]) {
        [dict setValue:on_line forKey:@"on_line"];
    }
    if (![BGFunctionHelper isNULLOfString:dump_energy_per]) {
        [dict setValue:dump_energy_per forKey:@"dump_energy_per"];
    }
    if (![BGFunctionHelper isNULLOfString:offline_day]) {
        [dict setValue:offline_day forKey:@"offline_day"];
    }
    if (![BGFunctionHelper isNULLOfString:device_type]) {
        [dict setValue:device_type forKey:@"device_type"];
    }
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//获取充电宝硬件故障
- (void)getPowerErrorInfoByAlias:(NSString *)alias eid:(NSString *)eid progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/charging/get_hardware_report";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//待维护页面的分页信息
- (void)waitingRepairByEid:(NSString *)eid page_size:(NSString *)page_size page_index:(NSString *)page_index offline_rate:(NSString *)offline_rate progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/store/maintenance_page";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:page_size forKey:@"page_size"];
    [dict setValue:page_index forKey:@"page_index"];
    
    if (![BGFunctionHelper isNULLOfString:offline_rate]) {
        [dict setValue:offline_rate forKey:@"offline_rate"];
    }
    
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];

}

//待维护页面的分页信息v2
- (void)waitingRepairByEid:(NSString *)eid page_size:(NSString *)page_size page_index:(NSString *)page_index date:(NSString *)date status:(NSString *)status progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v2/store/maintenance_page";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:page_size forKey:@"page_size"];
    [dict setValue:page_index forKey:@"page_index"];
    
    if (![BGFunctionHelper isNULLOfString:date]) {
        [dict setValue:date forKey:@"date"];
    }
    if (![BGFunctionHelper isNULLOfString:status]) {
        [dict setValue:status forKey:@"status"];
    }
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//待维护店铺的 充电宝详情 v2
- (void)waitingRepairDetailByEid:(NSString *)eid date:(NSString *)date charging_info_ids:(NSString*)charging_info_ids progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v2/store/maintenance_charging";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:date forKey:@"date"];
    [dict setValue:charging_info_ids forKey:@"charging_info_ids"];

    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];

}

//密码：熊大大版【初次】获取密码
- (void)powerGetPasswordFirstTimeByEid:(NSString *)eid alias:(NSString *)alias progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/xdddxh/get_password";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

//密码：熊大大版【再次】获取密码
- (void)powerGetPasswordAgainByEid:(NSString *)eid alias:(NSString *)alias step:(NSString *)step progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/xdddxh/again_password";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:alias forKey:@"alias"];
    [dict setValue:step forKey:@"step"];

    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

///v1/employee/all获取全部人员
- (void)getAllUsersByEid:(NSString *)eid oid:(NSString *)oid progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/employee/all";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    
    if (![BGFunctionHelper isNULLOfString:oid]) {
        [dict setValue:oid forKey:@"oid"];
    }
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
}

- (void)waitToHasUsedById:(NSString *)shopId eid:(NSString *)eid progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v1/store/already_stay";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:shopId forKey:@"id"];
    [dict setValue:eid forKey:@"eid"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];

}

//待维护店铺的 充电宝详情 v2 今日
- (void)waitingRepairDetailJinRiByEid:(NSString *)eid date:(NSString *)date charging_info_ids:(NSString*)charging_info_ids progressBlock:(ProgressBlock)progress success:(SuccessBlock)success failure:(FailureBlcok)failure{
    NSString *urlString = @"/app/v2/store/already_maintenance_charging";
    _url = [NSString stringWithFormat:@"%@%@",kHttpHeader,urlString];
    AFHTTPSessionManager *manager = [self creatManager];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setValue:eid forKey:@"eid"];
    [dict setValue:date forKey:@"date"];
    [dict setValue:charging_info_ids forKey:@"charging_info_ids"];
    
    [dict setValue:@"1" forKey:@"rf"];
    [dict setValue:kNowDate forKey:@"ts"];
    [dict setValue:kAppVersion forKey:@"v"];
    [dict setValue:urlString forKey:@"i"];
    [dict setValue:UDID forKey:@"udid"];
    
    [manager POST:_url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        if (progress) {
            progress(uploadProgress);
        }
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        if (success) {
            success(dic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
            if (error.code == -1009) {
                kAlert(@"似乎已断开与互联网的连接");
            }else{
                NSString *errorString = [NSString stringWithFormat:@"服务器错误，错误码：%ld",error.code];
                kAlert(errorString);
            }
        }
    }];
    
}


@end
